/*
 * Mesa.java
 *
 * Created on 12 de octubre de 2007, 03:08 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package data;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Entity class Mesa
 * 
 * @author Fanny Paola Vadillo Herrera
 * @author Luis Manuel Pineda Llano
 */
@Entity
@Table(name = "mesa")
@NamedQueries( {
        @NamedQuery(name = "Mesa.findByNumero", query = "SELECT m FROM Mesa m WHERE m.numero = :numero"),
        @NamedQuery(name = "Mesa.findBySeccion", query = "SELECT m FROM Mesa m WHERE m.seccion = :seccion"),
        @NamedQuery(name = "Mesa.findByMaxComensales", query = "SELECT m FROM Mesa m WHERE m.maxComensales = :maxComensales"),
        @NamedQuery(name = "Mesa.findAll", query = "SELECT m FROM Mesa m")
    })
public class Mesa implements Serializable {

    @Id
    @Column(name = "numero", nullable = false)
    private Short numero;

    @Column(name = "seccion", nullable = false)
    private String seccion;

    @Column(name = "maxComensales")
    private Short maxComensales;

    @OneToMany(mappedBy = "idMesa")
    private Collection<Orden> ordenCollection;

    @JoinColumn(name = "idUsuario", referencedColumnName = "username")
    @ManyToOne
    private Usuario idUsuario;
    
    /** Creates a new instance of Mesa */
    public Mesa() {
    }

    /**
     * Creates a new instance of Mesa with the specified values.
     * @param numero the numero of the Mesa
     */
    public Mesa(Short numero) {
        this.numero = numero;
    }

    /**
     * Creates a new instance of Mesa with the specified values.
     * @param numero the numero of the Mesa
     * @param seccion the seccion of the Mesa
     */
    public Mesa(Short numero, String seccion) {
        this.numero = numero;
        this.seccion = seccion;
    }

    /**
     * Gets the numero of this Mesa.
     * @return the numero
     */
    public Short getNumero() {
        return this.numero;
    }

    /**
     * Sets the numero of this Mesa to the specified value.
     * @param numero the new numero
     */
    public void setNumero(Short numero) {
        this.numero = numero;
    }

    /**
     * Gets the seccion of this Mesa.
     * @return the seccion
     */
    public String getSeccion() {
        return this.seccion;
    }

    /**
     * Sets the seccion of this Mesa to the specified value.
     * @param seccion the new seccion
     */
    public void setSeccion(String seccion) {
        this.seccion = seccion;
    }

    /**
     * Gets the maxComensales of this Mesa.
     * @return the maxComensales
     */
    public Short getMaxComensales() {
        return this.maxComensales;
    }

    /**
     * Sets the maxComensales of this Mesa to the specified value.
     * @param maxComensales the new maxComensales
     */
    public void setMaxComensales(Short maxComensales) {
        this.maxComensales = maxComensales;
    }

    /**
     * Gets the ordenCollection of this Mesa.
     * @return the ordenCollection
     */
    public Collection<Orden> getOrdenCollection() {
        return this.ordenCollection;
    }

    /**
     * Sets the ordenCollection of this Mesa to the specified value.
     * @param ordenCollection the new ordenCollection
     */
    public void setOrdenCollection(Collection<Orden> ordenCollection) {
        this.ordenCollection = ordenCollection;
    }

    /**
     * Gets the idUsuario of this Mesa.
     * @return the idUsuario
     */
    public Usuario getIdUsuario() {
        return this.idUsuario;
    }

    /**
     * Sets the idUsuario of this Mesa to the specified value.
     * @param idUsuario the new idUsuario
     */
    public void setIdUsuario(Usuario idUsuario) {
        this.idUsuario = idUsuario;
    }

    /**
     * Returns a hash code value for the object.  This implementation computes 
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (this.numero != null ? this.numero.hashCode() : 0);
        return hash;
    }

    /**
     * Determines whether another object is equal to this Mesa.  The result is 
     * <code>true</code> if and only if the argument is not null and is a Mesa object that 
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Mesa)) {
            return false;
        }
        Mesa other = (Mesa)object;
        if (this.numero != other.numero && (this.numero == null || !this.numero.equals(other.numero))) return false;
        return true;
    }

    /**
     * Returns a string representation of the object.  This implementation constructs 
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return "Mesa " + numero;
    }
    
}
